/**
 * 
 */
package qy.jalgotrade.broker.backtesting;

import java.time.ZonedDateTime;

import qy.jalgotrade.bar.Bar;
import qy.jalgotrade.broker.InstrumentTraits;
import qy.jalgotrade.broker.StopOrder;
import qy.jalgotrade.broker.fillstrategy.FillInfo;

/**
 * @author c-geo
 *
 */
public class BacktestingStopOrder extends StopOrder implements BacktestingOrder {

	private ZonedDateTime __accepted;

	/**
	 * Set to true when the limit order is activated (stop price is hit)
	 */
	private boolean __stopHit;

	/**
	 * @param action
	 * @param instrument
	 * @param stopPrice
	 * @param quantity
	 * @param instrumentTraits
	 * @throws Exception
	 */
	public BacktestingStopOrder(Action action, String instrument, double stopPrice, double quantity,
	        InstrumentTraits instrumentTraits) throws Exception {

		super(action, instrument, stopPrice, quantity, instrumentTraits);
		__accepted = null;
		__stopHit = false;
	}

	/* (non-Javadoc)
	 * @see qy.jalgotrade.broker.backtesting.BacktestingOrder#getAcceptedDateTime()
	 */
	@Override
	public ZonedDateTime getAcceptedDateTime() {

		return __accepted;
	}

	/* (non-Javadoc)
	 * @see qy.jalgotrade.broker.backtesting.BacktestingOrder#setAcceptedDateTime(java.time.ZonedDateTime)
	 */
	@Override
	public void setAcceptedDateTime(ZonedDateTime dateTime) {

		__accepted = dateTime;
	}

	/**
	 * 
	 * @return
	 */
	public boolean getStopHit() {

		return __stopHit;
	}

	/**
	 * 
	 * @param stopHit
	 */
	public void setStopHit(boolean stopHit) {

		__stopHit = stopHit;
	}

	/* (non-Javadoc)
	 * @see qy.jalgotrade.broker.backtesting.BacktestingOrder#process(qy.jalgotrade.broker.backtesting.BacktestingBroker, qy.jalgotrade.bar.Bar)
	 */
	@Override
	public FillInfo process(BacktestingBroker broker, Bar bar) {

		return broker.getFillStrategy().fillStopOrder(broker, this, bar);
	}
}
